package adv328;

import java.util.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class MapTest2 {
    public static void main(String[] args) {
        Map<String,String> m=new HashMap<>();
        m.put("点头","yes");
        m.put("来","come");
        m.put("去","go");
        m.put("老虎","tiger");
        m.put("猫","cat");
        m.put("猫","dog");
        m.put("not found","没有找到");
        m.put("空",null);
        m.put(null,"没有");

        String d = m.get("点头");
        System.out.println(d);
        String d2=m.get("颔首");
        System.out.println(d2);
        String d3=m.getOrDefault("颔首","没有找到");
        System.out.println(d3);
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>");
        String key="空";
        Set<String> keys = m.keySet();
        Collection<String> values = m.values();
        //m.containsValue()
        if(m.containsKey(key)){
            String value=m.get(key);
            System.out.println("有！值是："+value);
        }else{
            System.out.println("没有这个key");
        }
//        String value=m.get(key);
//        if(value==null){//不保险，因为HashMap支持null
//            System.out.println("没有");
//        }else{
//            System.out.println("有！值是："+value);
//        }
    }
}
